package gl.common;

import android.os.Handler;
import android.support.v4.view.ViewPager;

public class LoopViewPager extends Handler {
	ViewPager viewPager;
	private int item;
	private int max;
	int time = 3000;

	public LoopViewPager(ViewPager pager) {
		this.viewPager = pager;
	}

	public void start() {
		if (viewPager.getAdapter()==null) {
			return;
		}
		this.max = viewPager.getAdapter().getCount();
		postDelayed(new Runnable() {
			@Override
			public void run() {
				if (item >= max) {
					item = 0;
				}
				viewPager.setCurrentItem(item, true);
				item++;
				postDelayed(this, time);
			}
		}, time);
	}
	public void stop(){
		removeCallbacksAndMessages(null);
	}
	
}
